template.defaults.imports.CountdownTime = function (factEndDate) {
    var timestamp = (new Date()).valueOf();
    return factEndDate - timestamp;
};


    var loading = false; //状态标记
    var hasNextPage = false;
    var pageNo = 1;
    queryList(pageNo);

    //下拉刷新
    $("#aroundBox").pullToRefresh().on("pull-to-refresh", function () {
        $("#contentTo").html("");
        pageNo = 1;
        queryList(pageNo,function(){
            $("#aroundBox").pullToRefreshDone(); // 重置下拉刷新
        });
    });

    //上拉加载更多
    $('#aroundBox').infinite().on("infinite", function () {
        if (hasNextPage){
            pageNo++;
            queryList(pageNo,function(){
            },true);
        }        
    });

    function queryList(pageNo,callback,isMore){
        if (loading) return;
        loading = true;
        var params = {};
        params.start = (pageNo - 1) * 20;
        params.limit = 20;
        /* global getCookie*/
        params.token = getCookie('token');
        $.get('/antique/api/userAddress/query_list', params, function (result) {
            if (!isMore){
                /* global template */
                document.getElementById('contentTo').innerHTML = template('content', result.data);                
            } else {
                $("#contentTo").append(template('content', result.data));
            }
            hasNextPage = result.data.hasNextPage;
            if (!result.data.hasNextPage) {
                $('#loadmore').hide();
                $('#nomore').show();
            } else {
                $('#loadmore').show();
                $('#nomore').hide();
            }
            if (callback) callback();
            loading = false;

            
        });
    }

function delAdree (id) {
    $.confirm("您是否确认删除？", "", function() {
        $.post('/antique/api/userAddress/delete_address', { id:id,token:getCookie('token') }, function (result) {
            if (result.code == 0) {
                $.toast("删除成功！");
                $("#contentTo").html("");
                pageNo = 1;
                queryList(pageNo,function(){},true);
            } else {
             $.toast(result.message, "cancel");
            }
         });
      }, function() {
        //取消操作
      });
    
}
function defAdree (id) {
    $.post('/antique/api/userAddress/set_address_default', { id:id,isDefault:1,token:getCookie('token') }, function (result) {
        if (result.code == 0) {
            $.toast("操作成功！");
            $("#contentTo").html("");
            pageNo = 1;
            queryList(pageNo,function(){},true);
        } else {
            $.toast(result.message, "cancel");
        }
        });
     
}
